#include "CsvReader.h"
#include "K_Representative.h"

#include <iostream>
using::std::cout;
using std::endl;

#include <algorithm>
using std::for_each;

#include <fstream>
using std::ofstream;

int main()
{
	vector<Client> data = CsvReader::readFile("bank-data.csv");
	
	ofstream myfile;
	myfile.open ("algo result.txt");
	K_Representative k_represntative(5,false);
	K_Representative hybrid_k_represntative(7,true);
	vector<Cluster> clusters = k_represntative.compute(data);
	vector<Cluster> hybridClusters = k_represntative.compute(data);

	myfile << "Algo Category\n";
	for each (Cluster cluster in clusters)
	{
		myfile<< "**************NEW CLUSTER***************\n";
		myfile << "Representative\n";
		ClusterRepresentative  rep = k_represntative.ComputeQ(cluster);
		
		for each (qValue qval in rep)
		{
			for each (std::pair<double, double> val in qval)
			{
				myfile << val.first << ", " << val.second << " || ";
			}
			myfile << "\n";
		}

		myfile << "\n\n\n" ;
		myfile << "id       ageGroup       Sex     region     incomeClass     isMarried     nbChildren     hasCar     hasSaving     hasCurrent     hasMortgage    hasPep     \n";
		for each (Client cl in cluster)
		{
			myfile << cl.id << ", " << cl.ageGroup << ", " << cl.sex << ", " << cl.region << ", " 
				   << cl.incomeClass << ", " << cl.isMarried << ", " << cl.children << ", " 
				   << cl.hasCar << ", " << cl.hasSavingAccount << ", " << cl.hasCurrentAccount  
				   << ", " << cl.hasMortage << ", " << cl.hasPEP << "\n";
		}
		myfile << "\n******************************************\n\n";
	}
		
	myfile << "Algo Numerical\n";
	for each (Cluster cluster in hybridClusters)
	{
		myfile<< "**************NEW CLUSTER***************\n";
		myfile << "Representative\n";
		ClusterRepresentative  rep = k_represntative.ComputeQ(cluster);
		
		for each (qValue qval in rep)
		{
			for each (std::pair<double, double> val in qval)
			{
				myfile << val.first << ", " << val.second << " || ";
			}
			myfile << "\n";
		}

		myfile << "\n\n\n" ;
		myfile << "id       age       Sex     region     income     isMarried     nbChildren     hasCar     hasSaving     hasCurrent     hasMortgage    hasPep     \n";
		for each (Client cl in cluster)
		{
			myfile << cl.id << ", " << cl.age << ", " << cl.sex << ", " << cl.region << ", " 
				   << cl.income << ", " << cl.isMarried << ", " << cl.children << ", " 
				   << cl.hasCar << ", " << cl.hasSavingAccount << ", " << cl.hasCurrentAccount  
				   << ", " << cl.hasMortage << ", " << cl.hasPEP << "\n";
		}
		myfile << "\n******************************************\n\n";
	}

	myfile.close();
	return 0;
}